package org.mtmi.ui.scenes;

import org.eclipse.swt.graphics.Color;
import org.mtmi.ui.M;
import org.mtmi.ui.actions.IAction;
import org.mtmi.ui.actions.SeparatorAction;
import org.mtmi.ui.controls.Control;
import org.mtmi.ui.controls.ToolBar;
import org.mtmi.ui.controls.edits.AddSideButtonAction;
import org.mtmi.ui.scenes.actions.AddControlAction;
import org.mtmi.ui.scenes.actions.AddSceneAction;
import org.mtmi.ui.scenes.actions.ChangeSceneBackgroundAction;
import org.mtmi.ui.scenes.actions.RemoveControlAction;
import org.mtmi.ui.scenes.actions.RemoveSceneAction;
import org.mtmi.ui.scenes.actions.ToggleEditSceneModeAction;
import org.mtmi.ui.scenes.actions.ZOrderAction;

public class GlobalActionToolBar extends ToolBar
  implements ISceneManagerListener
{
	private Color bg;
	
	
	public GlobalActionToolBar( Scene scene, int flags ) {
		super( scene, flags|M.SCENE_EDITOR_CONTROL/*|M.VERTICAL*/ ); //TODO: vert for test
		
		SceneManager.getDefault().addSceneManagerListener( this );
		
		setBackgroundAlpha( 180 );
		
		addAction( new ToggleEditSceneModeAction(), false );
		addAction( new SeparatorAction(), false );
		addAction( new AddControlAction(), false );
		addAction( new RemoveControlAction(), false );
		addAction( new ZOrderAction(), false );
		addAction( new AddSideButtonAction(), false );
		addAction( new SeparatorAction(), false );
		addAction( new AddSceneAction(), false );
		addAction( new RemoveSceneAction(), true );
		addAction( new ChangeSceneBackgroundAction(), true );
		
		setForeground( COLOR.yellow );
		bg = CLR.darker( getForeground(), 0.5f );
		setBackground( bg );
		
		//change separator color:
		for( IAction a : getActions() ) {
			if( a instanceof SeparatorAction ) {
				Control c = getControl( a );
				c.setForeground( COLOR.yellow );
			}
		}
	}
	
	@Override
	public void dispose() {
		SceneManager.getDefault().removeSceneManagerListener( this );
		super.dispose();
		bg.dispose();
	}

	@Override
	public void sceneManagerModeChanged(boolean edit) {
		if( !edit ) {
			SceneManager.getDefault().removeSceneManagerListener( this );
			dispose();
		}
	}

	@Override
	public void sceneManagerSceneChanged( Scene new_scene, Scene old_scene ) {
		//I want this button available for all scenes
		setScene( new_scene );
	}

	@Override
	public void sceneManagerSceneAdded(Scene sceneAdded) {}

	@Override
	public void sceneManagerSceneRemoved(Scene sceneRemoved) {}
	
	
}
